package styx.lex;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class ScoreView extends SurfaceView implements SurfaceHolder.Callback {

	private SurfaceHolder holder;
	private int _width = 1;
	private int _height = 1;

	private int clr = 0xFFFF69B4;
	private int offX = 0;
	private int offY = 0;
	
	private Bitmap iconImage;
	private int iconWidth = 0;
	private int iconHeight = 0;
	
	public ScoreView(Context context) {
		super(context);

		this.holder = this.getHolder();
		holder.addCallback(this);

        Resources res = context.getResources();
		iconImage = BitmapFactory.decodeResource(res,
                R.drawable.heart);
		
		thread = new DrawThread();
	}

	public void draw()
	{
		Canvas c = this.holder.lockCanvas();
		c.drawColor(clr);
		int w = 0;
		int h = 0;
		while (w < _width)
		{
			h = 0;
			while (h < _height)
			{
				
				h += iconHeight;
			}
			w += iconWidth;
		}
		
		holder.unlockCanvasAndPost(c);
	}
	
	private DrawThread thread;
	
	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
		_width = width;
		_height = height;
	}

	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		thread.start();
		thread.running = true;
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		boolean retry = true;
		thread.running = false;
        while (retry) {
            try {
                thread.join();
                retry = false;
            } catch (InterruptedException e) {
            }
        }
	}
	
	private class DrawThread extends Thread
	{
		public boolean running = false;
		public void run(){
			while (running)
			{
				draw();
				try {
					sleep(80);
				} catch (InterruptedException e) {
				}
			}
		}
	}
}
